package com.xxh.dataaccess.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxh.dataaccess.dao.VideoLikeDao;
import com.xxh.dataaccess.entity.VideoLike;
import com.xxh.dataaccess.service.VideoLikeService;
import org.springframework.stereotype.Service;

/**
 * (VideoLike)表服务实现类
 *
 * @author makejava
 * @since 2021-02-12 15:46:17
 */
@Service("videoLikeService")
public class VideoLikeServiceImpl extends ServiceImpl<VideoLikeDao, VideoLike> implements VideoLikeService {

    //查询当前用户点赞状态
    @Override
    public boolean isLike(String bv, Integer uid) {

        QueryWrapper<VideoLike> wrapper = new QueryWrapper<>();
        wrapper.eq("like_user",uid);
        wrapper.eq("video_id",bv);
        VideoLike one = baseMapper.selectOne(wrapper);
        if(null==one){
            return false;
        }
        if(one.getStatus()!=0){
            return true;
        }
        return false;
    }

    //是否存在点赞记录
    @Override
    public VideoLike getLikeLog(String bv, Integer uid) {
        QueryWrapper<VideoLike> wrapper = new QueryWrapper<>();
        wrapper.eq("like_user",uid);
        wrapper.eq("video_id",bv);
        VideoLike one = baseMapper.selectOne(wrapper);
        return one;
    }

    @Override
    public boolean updateLikeStats(VideoLike videoLike) {
        int i = baseMapper.updateById(videoLike);
        if(i>0){
            return true;
        }else {
            return false;
        }
    }


}
